package net.shenru.os.task;

import android.os.AsyncTask;

public class WorkerAsyncTask extends AsyncTask<ITask, Integer, ITask> {

	private WorkerTaskListener listener;
	
	
	public WorkerAsyncTask(WorkerTaskListener listener) {
		super();
		this.listener = listener;
	}

	@Override
	protected ITask doInBackground(ITask... params) {
		ITask task = params[0];
		task.setStatue(TaskStatue.Runing);
		if(listener != null){
			listener.doInBackground(task);
		}
		task.getTaskBundle().exece();
		return task;
	}

	@Override
	protected void onPreExecute() {
		super.onPreExecute();
		if(listener != null){
			listener.onPreExecute();
		}
	}

	@Override
	protected void onPostExecute(ITask result) {
		super.onPostExecute(result);
		if(listener != null){
			listener.onPostExecute(result);
		}
	}

	@Override
	protected void onProgressUpdate(Integer... values) {
		super.onProgressUpdate(values);
	}

	@Override
	protected void onCancelled() {
		super.onCancelled();
	}

	/**
	 *工作任务监听对象
	 */
	public interface WorkerTaskListener{
		public ITask doInBackground(ITask task);
		public void onPreExecute();
		public void onPostExecute(ITask result);
	}
}
